package com.example.rabbitmqspringboot.demos.web.listener;

import com.example.rabbitmqspringboot.demos.web.pojo.Stud;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @ClassName: StudNackConsumer
 * @Description:
 * @Date 2024/04/11 10:27
 * @Author songshaoqiu
 **/
@Component
@Slf4j
public class StudNackConsumer {
    @RabbitListener(queues = {"normal-stud-queue"})
    public void listenStudMsg(Message message, Stud stud, Channel channel) throws IOException {
        log.info("接收到消息【{}】",stud);
        log.info("拒绝消费，并放入死信队列" );
        channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
    }


    @RabbitListener(queues = {"stud-nAck-queue"})
    public void listenDeadStudMsg(Message message, Stud stud, Channel channel) throws IOException {
        log.info("从死信队列接收到消息【{}】",stud);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }



    @RabbitListener(queues = {"formal_queue"})
    public void listenNewMsg(Message message, Stud stud, Channel channel) throws IOException {
        log.info("接收到消息【{}】",stud);
        log.info("拒绝消费，并放入死信队列" );
        channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
    }

    @RabbitListener(queues = {"dead_queue"})
    public void listenDeadRoutingKey(Message message, Stud stud, Channel channel) throws IOException {
        log.info("从死信队列接收到消息【{}】",stud);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
